import { Metadata } from 'next'
import { getBiddingsForSelection } from '@/lib/bidding/service'
import { GetBiddingsSchema, searchParamsCache } from '@/lib/bidding/validation'
import { BiddingsSelectionTable } from '@/lib/bidding/selection/biddings-selection-table'

export const metadata: Metadata = {
  title: '입찰선정',
  description: '개찰 이후 입찰가를 확인하고 낙찰업체를 선정할 수 있습니다.',
}

interface BiddingSelectionPageProps {
  searchParams: Promise<Record<string, string | string[] | undefined>>
}

export default async function BiddingSelectionPage({
  searchParams,
}: BiddingSelectionPageProps) {
  // URL 파라미터 검증
  const searchParamsResolved = await searchParams
  const search = searchParamsCache.parse(searchParamsResolved)

  // 데이터 조회
  const biddingsPromise = getBiddingsForSelection(search)

  return (
    <div className="flex flex-col gap-4 p-4">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">입찰선정</h1>
          <p className="text-muted-foreground">
            개찰 이후 입찰가를 확인하고 낙찰업체를 선정할 수 있습니다.
          </p>
        </div>
      </div>

      <BiddingsSelectionTable promises={Promise.all([biddingsPromise])} />
    </div>
  )
}